package com.goldze.mvvmhabit.ui.rvgroup;

import com.goldze.mvvmhabit.widght.expand.ExpandableViewModel;

import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

/**
 * create om  2020/11/16.
 * Created by  gaoxuge
 * email android_gaoxuge@163.com
 * 功能描述
 */
public class ExpandParentViewModel implements ExpandableViewModel {
    //给RecyclerView添加ObservableList
    public ObservableList<ExpandableViewModel> mDataList = new ObservableArrayList<>();
    public final long mIndex;

    public ObservableField<String> text = new ObservableField<>("");


    public ExpandParentViewModel(long index, String t) {
        mIndex = index;
        text.set(t);
    }
    public void initData(){
        mDataList.clear();
        for (int i = 0; i < 5; i++) {
            String text = "我是第" + i + "条";
            ExpandChildViewModel item = new ExpandChildViewModel(this, i, text);
            item.initData();
            mDataList.add(item);
        }
    }
    @Override
    public ExpandableViewModel getChild(int position) {
        return mDataList.get(position);
    }

    @Override
    public ObservableList<ExpandableViewModel> getItems() {
        return mDataList;
    }

    @Override
    public int getChildCount() {
        return mDataList.size();
    }

    @Override
    public long getId() {
        return mIndex;
    }

    @Override
    public long getChildId(int position) {
        return mDataList.get(position).getId();
    }
}
